<template>
    <ul class="mui-table-view">
        <li class="mui-table-view-cell mui-media" v-for="item in newslist" :key="item.id">
            <!-- 注意：用动态绑定的时候，拼接的字符串要用引号包起来，不然被当作参数 -->
            <router-link :to="'/home/newsinfo/'+item.id">
                <img class="mui-media-object mui-pull-left" :src="item.img_url">
                <div class="mui-media-body">
                    <h1>{{item.title}}</h1>
                    <p class='mui-ellipsis'>
                        <span>{{ item.add_time | dateFormat('YYYY-MM-DD hh:mm:ss')}}</span>
                        <span>点击：{{ item.click }}次</span>
                    </p>
                </div>
            </router-link>
        </li>
    </ul>
</template>

<script>
export default {
    data:function () {
        return {
            newslist:[]
        }
    },
    created:function () {
        this.getNewsList();
    },
    methods:{
        getNewsList:async function(){
            const {data} = await this.$http.get('/api/getnewslist');
            console.log(data);
            if(data.status===0) this.newslist=data.message;
            // this.$http.get('/api/getnewslist').then(res=>{
            //     console.log(res.data);
            //     if(res.data.status===0) this.newslist=res.data.message;
            // })
        }
    }
}
</script>

<style lang="scss" scoped>
.mui-media{
   h1{
       font-size: 14px;
   }
//    使用flex，弹性盒模型把span左右贴边
   .mui-ellipsis{
      color:blue;
      display: flex;
      justify-content: space-between;
      span{
          &:nth-child(1){
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
      }
   }  
}
</style>